package org.example.petitionplatformsystem.Spark;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.SparkSession;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置Spark相关的Bean

 */
@Configuration
public class SparkConfig {

    /**
     * 应用名称
     */
    @Value("${spark.app.name}")
    private String appName;

    /**
     * 设置Spark的master地址
     */
    @Value("${spark.master.uri}")
    private String sparkMasterUri;

    /**
     * 创建Spark配置
     * @return Spark配置
     */
    @Bean
    public SparkConf sparkConf() {
        return new SparkConf()
                .setAppName(appName)
                .setMaster(sparkMasterUri);
    }



    /**
     * 创建SparkSession
     * @return SparkSession实例
     */
    @Bean("sparkSession1")
    public SparkSession sparkSession() {
        return SparkSession.builder()
                .config(sparkConf())
                .getOrCreate();
    }
}
